package com.floreo.shopping.model;

import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author merzod
 */
public class ShoppingListTest {
    ShoppingList list;
    @Before
    public void setUp() throws Exception {
        list = new ShoppingList("testList");
    }

    @Test
    public void testAdd() throws Exception {
        Group g1 = new Group();
        Group g2 = new Group();
        Product product1 = new Product("milk", g1);
        Product product2 = new Product("bread", g2);
        Product product3 = new Product("bublic", g2);
        Quantity quantity = new Quantity();
        ShoppingItem item1 = new ShoppingItem(product1);
        ShoppingItem item2 = new ShoppingItem(product2, quantity);
        ShoppingItem item3 = new ShoppingItem(product3);
        list.add(item1);
        list.add(item2);
        list.add(item3);
        Assert.assertEquals(3, list.size());

        Assert.assertEquals(1, list.get(g1).size());
        Assert.assertEquals(2, list.get(g2).size());
        Assert.assertTrue(list.get(g1).contains(item1));
        Assert.assertTrue(list.get(g2).contains(item2));
        Assert.assertTrue(list.get(g2).contains(item3));
        Assert.assertFalse(list.get(g2).contains(item1));

        list.remove(item2);
        Assert.assertEquals(2, list.size());
        Assert.assertEquals(1, list.get(g2).size());
        Assert.assertTrue(list.get(g2).contains(item3));
    }
}
